<?php
use oxide\plugin\PluginAbstract;
use oxide\http\Context;

class AddThisPlugin extends PluginAbstract
{
   public function plug(Context $context) 
   {
      $this->register('ModuleContentInfoRenderContentFooter');      
   }
   
   public function onModuleContentInfoRenderContentFooter($event, $sender, $args = null)
   {
      $route = $this->getContext()->route;
      if($route->action != 'view') return;
      
      $services = $this->getConfigValue('share_services', 'facebook_like,google_plus,twitter,add_this');
      $services = explode(',', strtolower($services));
      array_walk($services, 'trim');
      
      
      $items = $args['terms'];
      $share_links = '<!-- AddThis Button BEGIN --><div class="addthis_toolbox addthis_default_style">';
      if(in_array('facebook_like', $services)) 
        $share_links .= '<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>';
      if(in_array('twitter', $services)) 
        $share_links .= '<a class="addthis_button_tweet"></a>';

      if(in_array('google_plus', $services)) 
        $share_links .= '<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>';
      if(in_array('add_this', $services)) 
        $share_links .= '<a class="addthis_counter addthis_pill_style"></a>';

      $share_links .= '</div><script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-51642f8968d857c0"></script><!-- AddThis Button END -->';
      
      $items[] = $share_links;
   }
}
?>
